﻿using System;
using Newtonsoft.Json.Linq;

namespace Sina.Altman.Weibo.SDK.Objects
{
    public class Pois
    {
        /// <summary>
        /// 搜索关键字返回所处位置集合
        /// </summary>
        /// <param name="json"></param>
        public Pois(string json)
            : this(JObject.Parse(json))
        {
        }

        private JObject __jobject;
        public Pois(JObject obj)
        {
            this.__jobject = obj;
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private Pos[] _poiItems;
        public Pos[] PoiItems
        {
            get
            {
                if (_poiItems == null)
                    _poiItems = (Pos[])JsonClassHelper.ReadArray<Pos>(JsonClassHelper.GetJToken<JArray>(__jobject, "pois"), JsonClassHelper.ReadStronglyTypedObject<Pos>, typeof(Pos[]));
                return _poiItems;
            }
        }

        public int TotalNumber
        {
            get
            {
                return JsonClassHelper.ReadInteger(JsonClassHelper.GetJToken<JValue>(__jobject, "total_number"));
            }
        }
    }

    /// <summary>
    /// 所处位置信息
    /// </summary>
    public class Pos
    {
        public Pos(string json):this(JObject.Parse(json))
        {

        }

        private JObject __jobject;
        public Pos(JObject obj)
        {
            this.__jobject = obj;
        }

        public string Pid
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "pid"));
            }
        }

        public string Longitude
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "longitude"));
            }
        }

        public string Latitude
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "latitude"));
            }
        }

        public string Name
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "name"));
            }
        }

        public string CityName
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "city_name"));
            }
        }

        public string ProvinceName
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "province_name"));
            }
        }

        public string Address
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "address"));
            }
        }

        public string Telephone
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "telephone"));
            }
        }

        public string Category
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "category"));
            }
        }

        public string Navigator
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "navigator"));
            }
        }

        public string PicUrl
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "pic_url"));
            }
        }
    }
}
